//
//  TTRoomViewController.swift
//  SSCodingOsx
//
//  Created by Toj on 3/16/21.
//  Copyright © 2021 TTProduct. All rights reserved.
//

import Cocoa

class TTRoomViewController: VNViewController {
    
    private lazy var leftItemViews: TTRoomLeftView = {
        let view = TTRoomLeftView()
        let visibleWidth = TTScreenVisibleWidth
        view.frame = CGRect(origin: .zero, size: CGSize(width: visibleWidth * 0.5, height: titleBarHeight))
        return view
    }()
    
    private lazy var rightItemView: TTRoomRightView = {
        let view = TTRoomRightView()
        let visibleWidth = TTScreenVisibleWidth
        view.frame = CGRect(origin: .zero, size: CGSize(width: visibleWidth * 0.5, height: titleBarHeight))
        return view
    }()
    
    private lazy var coursewareVC: TTCoursewareViewController = {
        let vc = TTCoursewareViewController()
        return vc
    }()
    
    private lazy var livesVC: TTLiveViewController = {
        let vc = TTLiveViewController()
        return vc
    }()
    
    private lazy var backgroundImageView: NSImageView = NSImageView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupMakeAddSubviews()
        
        setupMakeLayoutSubviews()
        
        setupMakeUI()
    }
    
    deinit {
        print(#function + className)
    }
}

// MARK: - override
extension TTRoomViewController {
    
    //    override func layout() {
    //        super.layout()
    //
    //    }
}

// MARK: - 点击事件
extension TTRoomViewController {
    // 点击题版
    @objc private func didTapPersistent(sender: NSButton) {
        
    }
}

// MARK: - setup
extension TTRoomViewController {
    
    private func setupMakeAddSubviews() {
        addChild(livesVC)
        addChild(coursewareVC)

        view.addSubview(backgroundImageView)
        view.addSubview(livesVC.view)
        view.addSubview(coursewareVC.view)
    }
    
    private func setupMakeLayoutSubviews() {
        backgroundImageView.snp.makeConstraints { (make) in
            make.left.bottom.right.equalTo(view)
            make.top.equalTo(titleBar.snp.bottom)
        }

        livesVC.view.snp.makeConstraints { (make) in
            make.width.equalTo(240)
            make.right.equalTo(view)
            make.top.equalTo(titleBar.snp.bottom)
            make.bottom.equalTo(view.snp.bottom).offset(-25)
        }

        coursewareVC.view.snp.makeConstraints { (make) in
            make.left.equalTo(5)
            make.right.equalTo(livesVC.view.snp.left).offset(-5)
            make.top.equalTo(titleBar.snp.bottom).offset(25)
            make.bottom.equalTo(view.snp.bottom).offset(-25)
        }
    }
    
    private func setupMakeUI() {
        view.tt_backgroundColor = NSColor.init(hexColor: "#A3DBF4")
        titleBar.isHidden = false
        titleBar.tt_backgroundColor = .white
        titleBar.lineColor = NSColor.init(hexColor: "#A5DBF3").tt_alpha(0.5)
        
        titleBar.leftMargin = 60
        titleBar.leftView = leftItemViews
        titleBar.rightMargin = 5
        titleBar.rightView = rightItemView
        
        coursewareVC.view.tt_backgroundColor = .yellow
    }
}

extension TTRoomViewController {
    
// func windowDidChangeScreen(_ notification: Notification) {
//
//     view.window?.zoom(nil)
// }
}
